package com.SuanFa.mati;

public class Aaa {
    static Object abc = new Object();
    int ticketNum = 10;
    public static void main(String[] args) throws InterruptedException {
         Aaa aaa = new Aaa();
        for (int i = 0; i < 20; i++) {
            new Thread(aaa::BuyTicket).start();
        }

    }
    private void BuyTicket() {
        synchronized (abc){
            if (ticketNum <= 0) {
                return;
            }

            System.out.println(Thread.currentThread().getName() + "正在卖第" + ticketNum + "张票");
            ticketNum--;
        }
    }
}
